package com.huawei.appmarket.service.video;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.RelativeLayout;
import com.huawei.appgallery.foundation.ui.framework.activity.AbstractBaseActivity;
import com.huawei.appmarket.support.video.VideoPlayer;
import com.huawei.appmarket.support.video.fullscreen.FullScreenVideoPlayProtocol;
import com.huawei.appmarket.support.video.fullscreen.FullScreenVideoPlayProtocol.Request;
import o.der.g;
import o.Logger;
import o.doo;
import o.ContentManager;
import o.ActivityUtil;
import o.evn;
import o.evo;
import o.evr;
import o.VideoNetChangeDialog;
import o.VideoNetChangeDialog.d;
import o.evt;

public class FullScreenVideoPlayActivity extends AbstractBaseActivity<FullScreenVideoPlayProtocol> {
    private final Runnable ʻॱ = new e();
    private final Handler ˊॱ = new Handler();
    VideoPlayer ˋॱ;
    int ˏॱ;
    String ͺ = "";
    evo ॱˊ;
    private int ॱˎ;
    private BroadcastReceiver ᐝॱ = new BroadcastReceiver(this) {
        final /* synthetic */ FullScreenVideoPlayActivity ˏ;

        {
            this.ˏ = r1;
        }

        @SuppressLint({"MissingPermission"})
        public void onReceive(Context context, Intent intent) {
            int ˊ = doo.ˊ(((ConnectivityManager) ContentManager.getInstant().getContext().getSystemService("connectivity")).getActiveNetworkInfo());
            if (ˊ != this.ˏ.ॱˎ) {
                this.ˏ.ॱˎ = ˊ;
                if (doo.ˊ(context)) {
                    this.ˏ.ˊॱ.removeCallbacks(this.ˏ.ʻॱ);
                    evn ˎ = evr.ˊ().ˎ();
                    if (ˎ != null) {
                        ˎ.ʼ();
                        return;
                    }
                    return;
                }
                this.ˏ.ˊॱ.postDelayed(this.ˏ.ʻॱ, 2000);
            }
        }
    };

    static class e implements Runnable {
        private e() {
        }

        public void run() {
            evn ˎ = evr.ˊ().ˎ();
            if (ˎ != null) {
                ˎ.ʼ();
            }
        }
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (ͺ()) {
            ᐝ();
            ॱˊ();
            ᐝॱ();
            ˉ();
            return;
        }
        finish();
    }

    private void ᐝ() {
        getWindow().getDecorView().setBackgroundColor(-16777216);
        View relativeLayout = new RelativeLayout(this);
        setContentView(relativeLayout);
        this.ˋॱ = new VideoPlayer(this, this) {
            final /* synthetic */ FullScreenVideoPlayActivity ˎ;

            public boolean ˊ() {
                this.ˎ.finish();
                return false;
            }
        };
        LayoutParams layoutParams = new RelativeLayout.LayoutParams(-1, -1);
        layoutParams.addRule(13);
        relativeLayout.addView(this.ˋॱ, layoutParams);
        this.ˋॱ.ˋ(this);
        this.ॱˊ = new evo((Context) this, g.ᐝᐝ);
        this.ˋॱ.setController(this.ॱˊ);
        this.ॱˊ.ॱॱ().setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ FullScreenVideoPlayActivity ˊ;

            {
                this.ˊ = r1;
            }

            public void onClick(View view) {
                Logger.ˎ("FullScreenVideoPlayActivity", "centerImage onclick");
                this.ˊ.ᐝॱ();
            }
        });
    }

    private boolean ͺ() {
        FullScreenVideoPlayProtocol fullScreenVideoPlayProtocol = (FullScreenVideoPlayProtocol) ʾ();
        if (fullScreenVideoPlayProtocol == null) {
            Logger.e("FullScreenVideoPlayActivity", "protocol is null");
            return false;
        }
        Request ॱ = fullScreenVideoPlayProtocol.ॱ();
        if (ॱ == null) {
            Logger.e("FullScreenVideoPlayActivity", "request is null");
            return false;
        }
        this.ͺ = ॱ.ˋ();
        this.ˏॱ = ॱ.ˊ();
        if (this.ˏॱ < 0) {
            this.ˏॱ = 0;
        }
        if (!TextUtils.isEmpty(this.ͺ)) {
            return true;
        }
        Logger.e("FullScreenVideoPlayActivity", "videoUrl:");
        return false;
    }

    private void ॱˊ() {
        if (this.ˋॱ != null && this.ॱˊ != null) {
            this.ˋॱ.setVideoBaseInfo(new b().ˋ(this.ͺ).ˎ("videoid_from_h5").ॱ());
            evt.ॱ(this.ͺ, this.ˏॱ);
        }
    }

    private void ᐝॱ() {
        evr.ˊ().ˏ(this.ˋॱ);
        this.ॱˎ = doo.ʼ(this);
        if (VideoNetChangeDialog.ˏ(this) && VideoNetChangeDialog.ˊ()) {
            ˊˋ();
        } else {
            ʼॱ();
        }
    }

    private void ʼॱ() {
        if (this.ˋॱ != null && this.ॱˊ != null) {
            this.ˋॱ.ᐝ();
            this.ˋॱ.setCurrentMode(11);
            this.ॱˊ.ˋ(11);
            setRequestedOrientation(-1);
        }
    }

    private void ˋˊ() {
        if (this.ˋॱ != null && this.ॱˊ != null && !this.ˋॱ.ॱᐝ()) {
            this.ˋॱ.ˋॱ();
        }
    }

    private void ˊˋ() {
        VideoNetChangeDialog o_evs = new VideoNetChangeDialog(this);
        o_evs.ˋ(new d(this) {
            final /* synthetic */ FullScreenVideoPlayActivity ˏ;

            {
                this.ˏ = r1;
            }

            public void ˊ() {
                this.ˏ.ʼॱ();
            }

            public void ॱ() {
                this.ˏ.finish();
            }
        });
        o_evs.ˋ();
    }

    public void onPause() {
        super.onPause();
        ˋˊ();
    }

    public void onDestroy() {
        if (this.ˋॱ != null) {
            this.ˋॱ.setCurrentMode(10);
            evr.ˊ().ॱॱ();
            evt.ॱ(this.ͺ, 0);
        }
        ActivityUtil.unregisterReceiver(this, this.ᐝॱ);
        this.ˊॱ.removeCallbacks(this.ʻॱ);
        super.onDestroy();
    }

    private void ˉ() {
        ActivityUtil.registerReceiver(this, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"), this.ᐝॱ);
    }
}
